package com.kaifamiao.www.ioDemo.do0923;

import java.lang.reflect.Modifier;

public class ClassOthers {

    public static void main(String[] args) {
        Class<Student> cl = Student.class;
        //getName()获取本类名称(全限定类名)
        String name = cl.getName();
        System.out.println(name);

        //getSimpleName()返回类的简称
        String sname = cl.getSimpleName();
        System.out.println(sname);

        //getSuperClass()返回此类的父类对象
        Class superclass = cl.getSuperclass();
        System.out.println(superclass);

        //getPackage()返回Package对象
        Package pk = cl.getPackage();
        System.out.println(pk);//package com.kaifamiao.www.ioDemo.do0923

        //getPackageName()JDK9提供了获取package名
        String pn = cl.getPackageName();
        System.out.println(pn);//com.kaifamiao.www.ioDemo.do0923
        System.out.println("================");
        //getModifiers返回类的修饰符的整数形式，可以使用 Modifier的toString(int) 查看
        int modifiers = cl.getModifiers();
        System.out.println(modifiers);
        System.out.println(Modifier.toString(modifiers));

        Class str = String.class;
        System.out.println(str.getModifiers());
        System.out.println(Modifier.toString(str.getModifiers()));
        System.out.println("=====");
        //getInterfaces()获取所有实现的接口数组
        Class[] interfaces = str.getInterfaces();
        for (Class inter :interfaces){
            System.out.println(inter);
        }
        System.out.println("这是一条分割线");
        //getClasses()获取class对象的public内部类
        Class[] classes = cl.getClasses();
        for (Class cls:classes){
            System.out.println(cls);
        }
        //getDeclaredClasses()获取所有的内部类
        Class<?>[] declaredClasses = cl.getDeclaredClasses();
        for (Class declar:declaredClasses){
            System.out.println(declar);
        }
    }
}
